package com.neutech.controller;

import com.google.gson.Gson;
import com.neutech.service.RegisterUserService;
import com.neutech.service.impl.RegisterUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/user/resisterLogin")
public class RegisterUserServlet extends HttpServlet {

    private RegisterUserService registerUserService = new RegisterUserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        String password = req.getParameter("password");

        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();
        out.print(gson.toJson(registerUserService.add(username,password)));
        out.close();
    }
}
